package com.sitech.portal.menus.service.impl;

import com.sitech.ibnms.core.BaseIbnmsService;
import com.sitech.portal.menus.service.MenuService;
import com.sitech.portal.system.dao.ISysModuleDao;
import com.sitech.portal.util.CommUtil;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;
import java.util.Map;

/**
 * Created by liujhc on 10/31.
 */
public class MenuServiceImpl extends BaseIbnmsService implements MenuService {

    @Autowired
    private ISysModuleDao sysModuleDao;

    @Override
    public List<Map> getSubSystems() {
        String loginId = getCurrentUser().getLOGIN_ID();
        return findSubModules(loginId, "0");
    }

    @Override
    public List<Map> getMenus(String systemId) {
        String loginId = getCurrentUser().getLOGIN_ID();
        return sysModuleDao.recursiveQuerySubModules(loginId, systemId);
    }

    @Override
    public List<Map> selectModuleForTokenInput(String input,String num) {
        return sysModuleDao.selectModuleForTokenInput(input,num,this.getCurrentUser().getLOGIN_ID());
    }

    private List findSubModules(String loginId, String parentId) {
        if (loginId.equalsIgnoreCase(CommUtil.USER_ADMIN)) {
            return sysModuleDao.findModuleListByParentId(parentId);
        } else {
            return sysModuleDao.findModuleListByLoginIDAndParentId(loginId, parentId);
        }
    }

}
